import type {CommandRegistryItem} from './command.type'

// 命令总线（核心注册）
export class CommandRegistry {
  private registryItemMap = new Map<string, CommandRegistryItem>();
  // 注册命令处理器
  register(item: CommandRegistryItem): void {
    const key = this.getMapKey(item.moduleName, item.commandName);
    
    if (this.registryItemMap.has(key)) {
      throw new Error(`Command [${item.moduleName}:${item.commandName}] already registered`);
    }
    
    this.registryItemMap.set(key, item);
  }

  get(module: string, command: string): CommandRegistryItem | undefined {
    return this.registryItemMap.get(this.getMapKey(module, command));
  }

  getMapKey(module: string, command: string): string {
    return `${module}:${command}`;
  }
}